const {request} = require("express");

const express = require("express");
const app = express();
const http = require("http").createServer(app);
const { initSocket } = require("./socket");

const mycors = require("./middleware/MyCors");
const { isAuthenticated } = require("./middleware/AuthMiddleWare");
const { isAdmin } = require("./middleware/AuthMiddleWare");
const { isEmployee } = require("./middleware/AuthMiddleWare");
const userController = require("./controller/UserController");
const meetingRoomController = require("./controller/MeetingRoomController");
const bookingOrderController = require("./controller/BookingOrderController");
const cancelBookingController = require("./controller/CancelBookingController");
const errMiddleWare = require("./middleware/ErrMiddleWare");

app.use(express.urlencoded());//这个插件专门分解参数name=zhangsan&pwd=123
app.use(express.json());//负责解析body里json格式的数据
app.use(mycors);

// app.use(isAuthenticated);
// app.use(isAdmin);
// app.use(isEmployee);

app.use("/api/users",userController);
app.use("/api/rooms",isAuthenticated,meetingRoomController);
app.use("/api/orders",isAuthenticated,bookingOrderController);
app.use("/api/cancel",isAuthenticated,cancelBookingController);
app.use(errMiddleWare);

// 启动服务后初始化 WebSocket
const server = app.listen(5000, () => {
  console.log("Server is running on port 5000");
});

// 初始化 WebSocket
initSocket(server);

app.listen(5000,()=>{
    console.log("Server is running on port 5000");
})